package org.ragdollcat.secondaiagent.controller;

import jakarta.annotation.Resource;
import org.ragdollcat.secondaiagent.agent.RagdollCatManus;
import org.ragdollcat.secondaiagent.app.LoveApp;
import org.ragdollcat.secondaiagent.app.RagdollCatApp;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.tool.ToolCallback;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/cat-agent")
public class RagdollCatController {


    @Resource
    private RagdollCatApp ragdollCatApp;

    @Resource
    private ToolCallback[] availableTools;

    @Resource
    private ChatModel dashScopeChatModel;


    /**
     * 常规对话
     * @param message
     * @param chatId
     * @return
     */
    @GetMapping(value = "/normal/chat",produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> doChat(String message,String chatId){
        Flux<String> stringFlux = ragdollCatApp.doChat(message, chatId);
        return stringFlux;
    }


    @GetMapping("/agent/chat")
    public SseEmitter doAgentChat(String message){
        RagdollCatManus ragdollCatManus = new RagdollCatManus(availableTools, dashScopeChatModel);
        return ragdollCatManus.runAsync(message);
    }

}
